package a.Handler;
import a.BeanFactory;
import a.annotation.Inject;
import a.InjectHandler;

import java.lang.reflect.Field;
public class FieldInjectHandler implements InjectHandler {
    public void execute(Object target, Class<?> targetClass, BeanFactory factory) throws IllegalAccessException, InstantiationException {
        for (Field field : targetClass.getDeclaredFields()){
            if (field.isAnnotationPresent(Inject.class)){
                field.setAccessible(true);
                String value = field.getAnnotation(Inject.class).value();
                Object bean = factory.getBean(value);
                field.set(target,bean);
            }
        }
    }
}
